﻿using _111.QywxDocument.Model;
using _111.QywxDocument.WeeklyReport.Model;
using guidHelper;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using MyDapperApi.Models;
using MyDapperApi.Services;
using MyDapperApi.Services.BaiLianAI;
using MyDapperApi.Services.ConsumerNum;
using MyDapperApi.Services.QywxBase;
using MyDapperApi.Services.QywxDocument.DigitalizationDemand;
using MyDapperApi.Services.QywxDocument.PrivateRoom;
using MyDapperApi.Services.QywxDocument.WeeklyReport;
using QYWXUpdate.DataModel;
using QYWXUpdate.DataModel.CheckInfo;
using System;

namespace MyDapperApi.Controllers;
/// <summary>
/// 【测试/调试接口】
/// <para>此控制器包含一系列用于功能验证和环境测试的接口，不应用于生产环境。</para>
/// </summary>
[ApiController]
[Route("api/[controller]")]
public class TestController : ControllerBase
{
    private readonly IAutoNetUpdateService _autoNetUpdateService;
    private readonly IDateBaseService _dateBaseService;
    private readonly INetDocumentService _netDocumentService;
    private readonly IDocDigitalizationDemandService _docDigitalizationDemandService;
    private readonly IQywxBaseService _qywxBaseService;
    private readonly IDocWeeklyReportService _docWeeklyReportService;
    private readonly ITestBaiLianService _testBaiLianService;
    private readonly IConsumerNumService _consumerNumService;
    private readonly IPrivateRoomService _privateRoomService;
    private readonly IConfiguration _configuration;

    public TestController(IAutoNetUpdateService autoNetUpdateService,
        IDateBaseService dateBaseService,
        INetDocumentService netDocumentService,
        IDocDigitalizationDemandService docDigitalizationDemandService,
        IQywxBaseService qywxBaseService,
        IDocWeeklyReportService docWeeklyReportService,
        ITestBaiLianService testBaiLianService,
        IConsumerNumService consumerNumService,
        IPrivateRoomService privateRoomService,
        IConfiguration configuration)
    {
        _autoNetUpdateService = autoNetUpdateService;
        _dateBaseService = dateBaseService;
        _netDocumentService = netDocumentService;
        _docDigitalizationDemandService = docDigitalizationDemandService;
        _qywxBaseService = qywxBaseService;
        _docWeeklyReportService = docWeeklyReportService;
        _testBaiLianService = testBaiLianService;
        _consumerNumService = consumerNumService;
        _privateRoomService = privateRoomService;
        _configuration = configuration;
    }

    /// <summary>
    /// **获取企业微信 AccessToken**
    /// </summary>
    /// <remarks>
    /// 调用企业微信API以获取有效的 AccessToken，用于其他接口调用。
    /// </remarks>
    /// <response code="200">成功获取到 Token。</response>
    /// <response code="500">企业微信API调用失败或配置错误。</response>
    [HttpGet("GetToken")]
    public async Task<IActionResult> GetAll()
    {
        var users = await _qywxBaseService.GetAccessTokenAsync("ww41ce2a97523f4d1a", "xKW0MRSs9azutLLPJt2hDi6gtpYDpdeas5azgxcbUnQ");
        return Ok(users);
    }
    /// <summary>
    /// **获取当前环境**
    /// </summary>
    [HttpGet("TestEnv")]
    public async Task<IActionResult> TestEnv()
    {
        var hangfireSettings = _configuration.GetSection("Environment");
        var isHangfireEnabled = hangfireSettings.GetValue<string>("Environment");
        return Ok(isHangfireEnabled);
    }
    /// <summary>
    /// 仅测试
    /// </summary>
    /// <returns></returns>
    [HttpGet("GetPrivateRoom")]
    public async Task<IActionResult> GetPrivateRoom()
    {
        var users = await _privateRoomService.GetRecordDetail("rpS0P9");
        return Ok(users);
    }
    /// <summary>
    /// 测试百炼推送消息
    /// </summary>
    /// <returns></returns>
    [HttpGet("TestBaiLian")]
    public async Task<IActionResult> TestBaiLian()
    {
        var users = await _testBaiLianService.TestPost();
        return Ok(users);
    }

    /// <summary>
    /// 测试推送在场客流
    /// </summary>
    /// <returns></returns>
    [HttpGet("TestConsumerNum")]
    public async Task<IActionResult> TestConsumerNum()
    {
        //await _consumerNumService.UpdateConsumerNum(DateTime.Now, "xshqs04", "09a85fa1-baef-44fd-91e4-cb3339ab802d");//武汉曲水
        //await _consumerNumService.UpdateConsumerNum(DateTime.Now, "xshqs06", "b6d9b1dd-c429-4f48-bc47-c0f30d003a51");//上海曲水
        await _consumerNumService.UpdateConsumerNum(DateTime.Now, "xshqs05", "65a45a58-14a4-4951-b2cb-7cc183edcc83");//苏州曲水
        await _consumerNumService.UpdateConsumerNum(DateTime.Now, "xshqs02", "418efe5f-6dc5-4075-b9c4-9a3c64be7830");//武汉曲水旭东
        await _consumerNumService.UpdateConsumerNum(DateTime.Now, "xshqs01", "3394d868-b64f-4666-b6a2-2a62205e06c6");//北京曲水
        return Ok();
    }

    /// <summary>
    /// 测试获取汇报
    /// </summary>
    /// <returns></returns>
    [HttpGet("TestDocWeekly")]
    public async Task<IActionResult> TestDocWeekly()
    {
        var users = await _docWeeklyReportService.UpdateDataBaseWeeklyReport(new UpdateDocumentRequest() { cursor = 0,limit = 100,dateTime = DateTime.Now });
        //var users = await _docWeeklyReportService.UpdateDataBaseWeeklyReport(new UpdateWeeklyReportRequest() { cursor = 0, limit = 10, dateTime = DateTime.Parse("2025-11-06 17:00:00") });
        return Ok(users);
    }
    /// <summary>
    /// 仅测试
    /// </summary>
    /// <returns></returns>
    [HttpGet("TestDocDegit")]
    public async Task<IActionResult> TestDocDegit()
    {
        var users = await _docDigitalizationDemandService.ClearDataBaseDigitalizationDemand();
        return Ok(users);
    }
    /// <summary>
    /// 测试基础数据库操作
    /// </summary>
    /// <returns></returns>
    [HttpGet("TestAdd")]
    public async Task<IActionResult> TestAdd()
    {
        var entity = new LogMsgEntity()
        {
            Id = ToolHelper.GUIDTO16(),
            Method = "Test",
            Class = "Test",
            Message = "Test",
            Created_On = DateTime.Now,
            Type = "Test",
        };
        var users = await _dateBaseService.AddBaseService(entity);
        return Ok(users);
    }
    /// <summary>
    /// 测试基础数据库查看操作
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost("TestPaging")]
    public async Task<IActionResult> TestPaging([FromBody]TestPagingRequest request)
    {
        var entity = new SgtqQueueDetailEntity();
        var users = await _dateBaseService.PagingBaseService(entity,request.PageIndex,request.PageSize,request.PagingType,"",request.OrderBy);
        return Ok(users);
    }
}